<template>
  <div class="login-main">
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">
          提交
        </van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
  import aesEncrypt from "@/assets/js/aesEncrypt/aesEncrypt";
  import {getAction, postAction} from "@/utils/request"
  export default {
    name: "Login",
    data() {
      return {
        username: '',
        password: '',
      };
    },
    methods: {
      onSubmit(values) {
        let self = this
        getAction('api/common/wx/getEncryptedString').then(data => {
          let res = data.data
          if (res.code == 200) {
            let obj = res.data
            //加密密码
            let password = aesEncrypt.encryption(self.password, obj.key, obj.iv)
            let params = {
              userName: self.username,
              userPass: password,
              userType: 'patient'
            }
            postAction('api/common/wx/accountLogin', params, true).then(data => {
              let res = data.data
              if (res.code == 200) {
                let userInfo = res.data.userVo
                let info = {  //个人信息
                  "appKey": appKey,
                  "userType": userInfo.userType,
                  "userName": userInfo.userNickname,
                  "userId": userInfo.id,
                  "userImg": userInfo.userImg,
                  "ryToken": userInfo.imTokens
                }
              }
            })
          }
        })
      },
    },
  }
</script>

<style lang="stylus" scoped>
  .login-main
    height 100vh
    display flex
    justify-content center
    align-items center
</style>